import axios from "axios";

// import {
// 	ElMessageBox
// } from 'element-plus';

// axios 请求根路径
axios.defaults.baseURL = '/api';

//post请求头
axios.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
//设置超时
axios.defaults.timeout = 100000;

axios.interceptors.request.use(
	config => {
		return config;
	},
	error => {
		return Promise.reject(error);
	}
);

axios.interceptors.response.use(
	response => {
		if (response.status === 200) {
			return Promise.resolve(response);
		} else {
			return Promise.reject(response);
		}
	},
	error => {

		// ElMessageBox(JSON.stringify(error), '请求异常', {
		// 	confirmButtonText: '确定',
		// 	callback: action => {}
		// });
		console.log(JSON.stringify(error));
	}
);
export default {
	post(url, data) {
		return new Promise((resolve, reject) => {
			axios({
				method: 'post',
				url,
				data: data,
			})
				.then(res => {
					resolve(res.data)
				})
				.catch(err => {
					reject(err)
				});
		})
	},

	get(url, data) {
		return new Promise((resolve, reject) => {
			axios({
				method: 'get',
				url,
				params: data,
			})
				.then(res => {
					resolve(res.data)
				})
				.catch(err => {
					reject(err)
				})
		})
	}
};
